package demo.practice.competition;

import java.util.Arrays;
import java.util.List;

public class P5640 {

    public static void main(String[] args) {
        P5640 p5640= new P5640();
        p5640.maximizeXor(new int[]{0,1,2,3,6},new int[][]{{3,1},{1,3},{5,6}});
    }

    //java 位运算   &位与  |或  ^异或   ~非
    public int[] maximizeXor(int[] nums, int[][] queries) {

        int len = queries.length;
        int[] target = new int[len];
        int len2 = nums.length;


//        int qmax=-1;
//        for(int i=0;i<queries.length;i++){
//            if(queries[i][1]>qmax)
//                qmax=queries[i][1];
//        }
//
//        int finalQmax = qmax;
//        int[] ints = Arrays.stream(nums).filter(i -> i <= finalQmax).toArray();
//        Arrays.sort(ints);
//        Arrays.sort(nums);



        for (int i = 0; i < len; i++) {
            int max = -1;
            int maxi = queries[i][1];

            for (int j = 0; j < len2; j++) {
                if (nums[j] <= maxi) {
                    int valXOR = queries[i][0] ^ nums[j];
                    //max = Math.max(valXOR, max);
                    if (valXOR>max)
                        max=valXOR;
                }
            }

//            int valXOR=queries[i][0] ^ nums[len2-1];
            target[i] = max;
        }
        return target;
    }

}
